<?php
/**
 * 
 * User/IndexAction.class.php (前台会员中心模块)
 *
 * @package      	jgsat
 * @author          liuxun QQ:147613338 <admin@jgsat.cn>
 * @copyright     	Copyright (c) 2008-2011  (http://www.jgsat.com)
 * @license         http://www.jgsat.com/license.txt
 * @version        	jgsat企业网站管理系统 v2.1 2012-10-08 jgsat.cn $
 */
if(!defined("JGsat")) exit("Access Denied");
class HelpAction extends BaseAction
{

	function _initialize()
    {	
		parent::_initialize();

		unset($_POST['status']);
		unset($_POST['groupid']);
		unset($_POST['amount']);
		unset($_POST['point']);
		$_GET =get_safe_replace($_GET);
        
    }

    public function index($catid='',$module='')
    {
        $this->Urlrule =F('Urlrule');
        if(empty($catid)) $catid =  intval($_REQUEST['id']);
        $p= max(intval($_REQUEST[C('VAR_PAGE')]),1);

        if($catid){
            $cat = $this->categorys[$catid];
            $bcid = explode(",",$cat['arrparentid']);
            $jgbcid = $bcid;
            $bcid = $bcid[1];
            if($bcid == '') $bcid=intval($catid);
            if(empty($module))$module=$cat['module'];
            $this->assign('module_name',$module);
            unset($cat['id']);
            $this->assign($cat);
            $cat['id']=$catid;
            $this->assign('jgbcid',$jgbcid);
            $this->assign('catid',$catid);
            $this->assign('bcid',$bcid);
        }
        if($cat['readgroup'] && $this->_groupid!=1 && !in_array($this->_groupid,explode(',',$cat['readgroup']))){$this->assign('jumpUrl',URL('User-Login/index'));$this->error (L('NO_READ'));}
        $fields = F($this->mod[$module].'_Field');
        foreach($fields as $key=>$r){
            $fields[$key]['setup'] =string2array($fields[$key]['setup']);
        }
        $this->assign ( 'fields', $fields);


        $seo_title = $cat['title'] ? $cat['title'] : $cat['catname'];
        $this->assign ('seo_title',$seo_title);
        $this->assign ('seo_keywords',$cat['keywords']);
        $this->assign ('seo_description',$cat['description']);


        if($module=='Guestbook'){
            $where['status']=array('eq',1);
            $this->dao= M($module);
            $count = $this->dao->where($where)->count();
            if($count){
                import ( "@.ORG.Page" );
                $listRows =  !empty($cat['pagesize']) ? $cat['pagesize'] : C('PAGE_LISTROWS');
                $page = new Page ( $count, $listRows );
                $page->urlrule = geturl($cat,'');
                $pages = $page->show();
                $field =  $this->module[$cat['moduleid']]['listfields'];
                $field =  $field ? $field : '*';
                $list = $this->dao->field($field)->where($where)->order('createtime desc,id desc')->limit($page->firstRow . ',' . $page->listRows)->select();
                $this->assign('pages',$pages);
                $this->assign('list',$list);
            }
            $template = $cat['module']=='Guestbook' && $cat['template_list'] ? $cat['template_list'] : 'index';
            $this->display(THEME_PATH.$module.'_'.$template.'.html');
        }elseif($module=='Feedback'){
            $template = $cat['module']=='Feedback' && $cat['template_list'] ? $cat['template_list'] : 'index' ;

            $this->display(THEME_PATH.$module.'_'.$template.'.html');
        }elseif($module=='Page'){
            $modle=M('Page');
            $data = $modle->find($catid);
            unset($data['id']);

            //分页
            $CONTENT_POS = strpos($data['content'], '[page]');
            if($CONTENT_POS !== false) {
                $urlrule = geturl($cat,'',$this->Urlrule);
                $urlrule[0] =  urldecode($urlrule[0]);
                $urlrule[1] =  urldecode($urlrule[1]);
                $contents = array_filter(explode('[page]',$data['content']));
                $pagenumber = count($contents);
                for($i=1; $i<=$pagenumber; $i++) {
                    $pageurls[$i] = str_replace('{$page}',$i,$urlrule);
                }
                $pages = content_pages($pagenumber,$p, $pageurls);
                //判断[page]出现的位置
                if($CONTENT_POS<7) {
                    $data['content'] = $contents[$p];
                } else {
                    $data['content'] = $contents[$p-1];
                }
                $this->assign ('pages',$pages);
            }

            $template = $cat['template_list'] ? $cat['template_list'] :  'index' ;
            $this->assign ($data);
            $this->display(THEME_PATH.$module.'_'.$template.'.html');

        }else{

            if($catid){
                $seo_title = $cat['title'] ? $cat['title'] : $cat['catname'];
                $this->assign ('seo_title',$seo_title);
                $this->assign ('seo_keywords',$cat['keywords']);
                $this->assign ('seo_description',$cat['description']);


                $where = " status=1 ";
                if($cat['child']){
                    $where .= " and catid in(".$cat['arrchildid'].")";
                }else{
                    $where .=  " and catid=".$catid;
                }
                if(empty($cat['listtype'])){
                    $this->dao= M($module);
                    $count = $this->dao->where($where)->count();
                    if($count){
                        import ( "@.ORG.Page" );
                        $listRows =  !empty($cat['pagesize']) ? $cat['pagesize'] : C('PAGE_LISTROWS');
                        $page = new Page ( $count, $listRows );
                        $page->urlrule = geturl($cat,'',$this->Urlrule);
                        $pages = $page->preshow();
                        $field =  $this->module[$this->mod[$module]]['listfields'];
                        $field =  $field ? $field : 'id,catid,userid,url,username,title,title_style,keywords,description,thumb,createtime,hits,pic';
                        $list = $this->dao->field($field)->where($where)->order('listorder ,createtime desc,id desc')->limit($page->firstRow . ',' . $page->listRows)->select();
                        $this->assign('pages',$pages);
                        $this->assign('list',$list);
                    }
                    $template_r = 'list';
                }else{
                    $template_r = 'index';
                }
            }else{
                $template_r = 'list';
            }
            $template = $cat['template_list'] ? $cat['template_list'] : $template_r;

            $this->display($module.':'.$template);
        }
    }






}
?>